package versi.vitro.oaiserviceprovider.service.jena.impl;

import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;

import versi.vitro.oaiserviceprovider.helper.TestConstant.Connection;

public class JenaConnectionManagerIntegrationTest {

    @DataProvider(name = "incorrectParametersForUnsuccessfulLogin")
    public Object[][] incorrectParametersForUnsuccessfulLogin() {
	return new Object[][] {
    	// without host
    	{ null, Connection.JENA_DATABASE, Connection.JENA_USER, Connection.JENA_PASS },
    	// without user name
    	{ Connection.JENA_HOST, Connection.JENA_DATABASE, null, Connection.JENA_PASS },
    	// without password
    	{ Connection.JENA_HOST, Connection.JENA_DATABASE, Connection.JENA_USER, null },
    	// wrong user-password matching
    	{ Connection.JENA_HOST, Connection.JENA_DATABASE, Connection.JENA_USER + "wrong", Connection.JENA_PASS + "wrong" },
    	// wrong host
    	{ "wrong" + Connection.JENA_HOST, Connection.JENA_DATABASE, Connection.JENA_USER, Connection.JENA_PASS },
    	// wrong database
    	{ Connection.JENA_HOST, "wrong" + Connection.JENA_DATABASE, Connection.JENA_USER, Connection.JENA_PASS } };
    }

    @Test
    public void testLoginJenaOperation() {
	String jenaDBurl = "jdbc:mysql://" + Connection.JENA_HOST + ":" + 3306 + "/" + Connection.JENA_DATABASE;
	String username = Connection.JENA_USER;
	String password = Connection.JENA_PASS;
	JenaConnManagerImpl jenaConnManagerImpl = new JenaConnManagerImpl(jenaDBurl, username, password);
	jenaConnManagerImpl.connect();
	jenaConnManagerImpl.disconnect();
    }

    @Test(expectedExceptions = { RuntimeException.class }, dataProvider = "incorrectParametersForUnsuccessfulLogin")
    public void testUnsuccessfulLoginWithWrongParameters(String host, String databaseName, String username, String password) throws Exception {
	String jenaDBurl = "jdbc:mysql://" + host + ":" + 3306 + "/" + databaseName;
	JenaConnManagerImpl jenaConnManagerImpl = new JenaConnManagerImpl(jenaDBurl, username, password);
	jenaConnManagerImpl.connect();
	jenaConnManagerImpl.disconnect();
    }
}
